home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Str / c / LeafName < prev    next >
Text File  |  1995-07-22  |  2KB  |  47 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Misc.Leafname.c
  12.     Author:  Copyright © 1994 Erik de Kort
  13.     Version: 1.01 (26 Jun 1994)
  14.     Purpose: Determine the leaf-name of a file given a legal pathname
  15.     Mods:    12 Jul 1995 - JPS - Changed name to Str_LeafName.
  16. */
  17.  
  18.  
  19. #include "DeskLib:Str.h"
  20.  
  21.  
  22. /* Str_LeafName() ----------------------------------------------------------
  23.  * Return a pointer to the leaf of 'FullPath'.
  24.  * Note that this pointer is within the 'FullPath' string.
  25.  * If no separator (dot or colon) is encountered in FullPath, then the
  26.  * pointer FullPath is returned.
  27.  *
  28.  * It is assumed that if any colons appear, then you either have a proper
  29.  * pathname (SCSI::...) in which case a dot will appear before the leafname,
  30.  * or you're using a path MyPath:FileName, so : is treated the same as .
  31.  */
  32.  
  33. extern char *Str_LeafName(char *path)
  34. {
  35.   char *leaf, ch = '.';
  36.  
  37.   do
  38.   {
  39.     if (ch == '.' || ch == ':')
  40.       leaf = path ;
  41.   } 
  42.   while ( (ch = *(path++)) != '\0') ;
  43.   
  44.   return(leaf) ;
  45.   /* cc warns 'leaf' may be used before being set    */
  46. }
  47.